package cc.plumgo.j2me.utils;

import javax.microedition.lcdui.game.GameCanvas;

public abstract class CustomCanvas extends GameCanvas implements Runnable {	
	public static final int GAME_PULSE = 100;
	
	public static final int GLB_UI = 0;
	public static final int GLB_YO = 1;
	public static final int GLB_STATE_NUM = 2;
	
	public static CustomCanvas canvas;
	protected int state;
	protected boolean isRunning;
	protected CustomCanvas() {
		super(true);
	}
	
	public void run() {
		long t1 = System.currentTimeMillis();
		long t2 = t1;
		while(isRunning){
			t2 = System.currentTimeMillis();
			if( t2 - t1 > GAME_PULSE ){
				t1 = t2;
				process();
			}
		}
	}

	public void start() {
		isRunning = true;
		Thread thread = new Thread(this);
		thread.start();
	}
	
	public void stop() {
		isRunning = false;
	}

	abstract public void process();
}
